"""
文件复制的本质:
编写一个程序,讲一个文件(类型不确定)复制一份
"""
file_source_path = input("输入要复制的文件:")
file_target_path = file_source_path.split("/")[-1]

file_source = open(file_source_path, 'rb')
file_target = open(file_target_path, 'wb')
while True:
    # 边读边写
    data = file_source.read(1024)
    if not data:
        break
    file_target.write(data)

file_target.close()
file_source.close()

# 报错:一个with只能搞一个对象
# with open(file_source_path, 'rb'), open(file_target_path, 'wb') as file_source, file_target:
#     while True:
#         data = file_source.read(1024)
#         if not data:
#             break
#         file_target.write(data)

# 缓冲区的验证
# while True:
#     msg = input(">>")
#     if not data:
#         break
#     file_target.write(msg)
# 程序结束后,刷新缓存,将缓冲区内容导入到硬盘中
